package com.dst.smart.dao.impl.factory;

import java.util.ArrayList;
import java.util.List;

import com.dst.smart.app.MyApplication;
import com.dst.smart.model.ModeList;

public class ModeListFactory {
	public static List<ModeList> list = new ArrayList<ModeList>();

	static {
		if (list.size() == 0) {
			list = MyApplication.getInstance().getWidgetDataBase()
					.getModeList();
		}
	}

	public static List<ModeList> getAll() {
		if (list.size() == 0) {
			list = MyApplication.getInstance().getWidgetDataBase()
					.getModeList();
		}
		return list;
	}

	public static List<ModeList> getModeDevice(int modeId) {
		List<ModeList> resultList = new ArrayList<ModeList>();
		if (list.size() == 0) {
			list = MyApplication.getInstance().getWidgetDataBase()
					.getModeList();
		}
		for (ModeList modeList : list) {
			if (modeList.getModeId() == modeId) {
				resultList.add(modeList);
			}

		}
		return resultList;
	}

	public static void delete(int id) {

		for (ModeList modeList : list) {
			if (modeList.getId() == id) {
				list.remove(modeList);
				break;
			}

		}
	}

	public static void clearList() {
		list = MyApplication.getInstance().getWidgetDataBase().getModeList();
	}

}
